home *** CD-ROM | disk | FTP | other *** search
/ Especial Multimedia / Especial Multimedia.iso / Multimed / Prg / GLYPHGRD.ZIP / UNIT1.PAS < prev   
Pascal/Delphi Source File  |  1997-09-14  |  3KB  |  132 lines

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Grids, StdCtrls, FileCtrl, ExtCtrls, Menus, Spin;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     MainMenu1: TMainMenu;
  12.     File1: TMenuItem;
  13.     Exit1: TMenuItem;
  14.     Edit1: TMenuItem;
  15.     Copy1: TMenuItem;
  16.     Panel2: TPanel;
  17.     DriveComboBox1: TDriveComboBox;
  18.     DirectoryListBox1: TDirectoryListBox;
  19.     MagFactor: TSpinEdit;
  20.     Magnification: TLabel;
  21.     DrawGrid1: TDrawGrid;
  22.     procedure DriveComboBox1Change(Sender: TObject);
  23.     procedure DirectoryListBox1Change(Sender: TObject);
  24.     procedure FormCreate(Sender: TObject);
  25.     procedure DrawGrid1DrawCell(Sender: TObject; Col, Row: Longint;
  26.       Rect: TRect; State: TGridDrawState);
  27.     procedure Exit1Click(Sender: TObject);
  28.     procedure Copy1Click(Sender: TObject);
  29.     procedure MagFactorChange(Sender: TObject);
  30.   private
  31.     { Private declarations }
  32.     GFList : TStringList;
  33.     procedure InitNewDir;
  34.   public
  35.     { Public declarations }
  36.   end;
  37.  
  38. var
  39.   Form1: TForm1;
  40.  
  41. implementation
  42.  
  43. {$R *.DFM}
  44.  
  45. uses Clipbrd;
  46.  
  47. procedure TForm1.FormCreate(Sender: TObject);
  48. begin
  49.   GFList := TStringList.Create;
  50.   DrawGrid1.ColWidths[0] := 64;
  51.   DrawGrid1.ColWidths[1] := 128;
  52.   {irectoryListBox1.Directory := 'd:\delphi\images\buttons';}
  53.   InitNewDir;
  54. end;
  55.  
  56. procedure TForm1.DriveComboBox1Change(Sender: TObject);
  57. begin
  58.   DirectoryListBox1.Drive := DriveComboBox1.Drive;
  59. end;
  60.  
  61. procedure TForm1.InitNewDir;
  62. var
  63.   Result : Integer;
  64.   sr: TSearchRec;
  65. begin
  66.   If GFList.Count > 0 then
  67.     GFList.Clear;
  68.   Result := FindFirst(DirectoryListBox1.Directory + '\*.bmp', faAnyFile, sr);
  69.   while result = 0 do
  70.   begin
  71.     if sr.Attr > 0 then
  72.       GFList.Add(sr.Name);
  73.     Result := FindNext(sr);
  74.   end;
  75.   DrawGrid1.RowCount := GFList.Count+1;
  76. end;
  77.  
  78. procedure TForm1.DirectoryListBox1Change(Sender: TObject);
  79. begin
  80.   InitNewDir;
  81. end;
  82.  
  83. procedure TForm1.DrawGrid1DrawCell(Sender: TObject; Col, Row: Longint;
  84.   Rect: TRect; State: TGridDrawState);
  85. var
  86.   dg : TDrawGrid;
  87.   bm : TBitmap;
  88.   SRect, DRect : TRect;
  89. begin
  90.   dg := (Sender as TDrawGrid);
  91.   if row = 0 then
  92.   else if Col = 0 then
  93.     begin
  94.       { Draw Bitmap }
  95.       bm := TBitmap.Create;
  96.       bm.LoadFromFile(GFList.Strings[Row-1]);
  97.       SRect  := classes.Rect(0, 0, bm.Width, bm.Height);
  98.       DRect  := classes.Rect(Rect.Left+2, Rect.Top + 1 ,
  99.                 Rect.Left + 3 + bm.Width * MagFactor.Value,
  100.                 Rect.Top + 1 + bm.Height * MagFactor.Value);
  101.       dg.Canvas.BrushCopy(DRect, bm, SRect,
  102.         bm.Canvas.Pixels[0,bm.Height-1]);
  103.       bm.Free;
  104.     end
  105.   else
  106.     { Print Filename }
  107.     dg.Canvas.TextRect(Rect, Rect.Left + 2,
  108.       Rect.Top + 1, GFList.Strings[Row-1]);
  109. end;
  110.  
  111. procedure TForm1.Exit1Click(Sender: TObject);
  112. begin
  113.   Close;
  114. end;
  115.  
  116. procedure TForm1.Copy1Click(Sender: TObject);
  117. var
  118.   r : TGridRect;
  119. begin
  120.   r := DrawGrid1.Selection;
  121.   Clipboard.AsText := DirectoryListBox1.Directory
  122.     + '\' + GFList.Strings[r.Top-1];
  123. end;
  124.  
  125. procedure TForm1.MagFactorChange(Sender: TObject);
  126. begin
  127.   DrawGrid1.DefaultRowHeight := 20 * MagFactor.Value;
  128.   DrawGrid1.ColWidths[0]     := 50 * MagFactor.Value;
  129. end;
  130.  
  131. end.
  132.